#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
int main()
{
    char a[10000] = { 0 }, c = 0;
    int i = 0, n = 0, f = 1;
    do {
        scanf("%c", &c);
        if ((c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F') || (c >= '0' && c <= '9'))
        {
            a[i++] = c;
            n++;
        }
        else if (c == '-' && n == 0)
        {
            f = 0;
        }

    } while (c != '#');
    int j = 1, sum = 0;
    for (i = n - 1; i >= 0; i--)
    {
        if (a[i] >= 'a' && a[i] <= 'f')
        {
            sum += j * (a[i] - 'a' + 16);
        }
        else if (a[i] >= 'A' && a[i] <= 'F')
        {
            sum += j * (a[i] - 'A' + 16);
        }
        else if (a[i] >= '0' && a[i] <= '9')
        {
            sum += j * (a[i] - '0' + 16);
        }
        j *= 16;
    }
    if (sum == 0)printf("0\n");
    else if (f == 0)printf("-%d", sum);
    else printf("%d", sum);

    return 0;
}